Call By Value | Call By Reference |
---|---|
When an argument is passed by value, any modification made in formal argument in the called function are not reflected back to the actual argument in the calling function. | It is required when you want to modify the formal argument and see those changes reflected in the actual argument in the calling function. |
The formal arguments gets separate memory and value of actual argument is assigned to corresponding formal argument. | No separate memory is allocated to the formal reference argument as only reference to the actual argument are created in the called function. |
The argument passed by value may be a constant, a variable or an expression. | The argument passed by reference must by a variable. |
It is a default mechanism of argument passing. | User needs to specify this method of passing argument. |
A function in which argument are passed by value can return only one value using return statement. | A function in which arguments are passed by reference can return more than one value. |
It is not suitable for passing argument of large size as separate copy of it consumes a lot of memory space. | It is suitable for passing arguments of large sizes as no separate copy is made in called function. |
Formal argument in function declarator in case of call by value is declared as f1(int i) { } |
Formal argument in function declarator in case of call by reference is declared as f1(int & i) { } |